/*EXPRESS服务器模板创建日期2017年09月25日16:13:14 Myweb*/
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const compression = require('compression');

app.all('*', function (req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    // res.header("Access-Control-Allow-Headers", "Accept, X-Access-Token, X-Application-Name, X-Request-Sent-Time, token");
    res.header("Access-Control-Allow-Headers", "*");
    res.header("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
    res.header("Access-Control-Allow-Credentials", true);

    next();
});

let https = require('https');
let fs = require('fs');
let options = {
    key: fs.readFileSync('./keys/private.key'),
    cert: fs.readFileSync('./keys/full_chain.pem'),
    requestCert: false,
    rejectUnauthorized: false
};


//极验证
const Geetest = require('gt3-sdk');
app.use(bodyParser.urlencoded({extended: false, uploadDir: './public/upload'}));

require('./db/db.js');

const nunjucks = require('nunjucks');//引入nunjucks
nunjucks.configure('views', {//指定文件目录
    autoescape: true,
    express: app,
    noCache: true
});

app.use(compression());

const session = require('express-session');
app.use(session({
    secret: 'myweb',
    resave: true,
    saveUninitialized: true
}));

app.use('/static', express.static('./public'));

//扩展接口
app.use(require('./router/extend'));

//微信接口
app.use(require('./router/wechat'));

//动态接口路由
app.use(require('./router/dynamic'));

//vue接口
app.use(require('./router/vue'));

//nas相关接口
app.use(require('./nas/nas'));


//改版HOME
app.use(require('./router/home'));

//404处理
app.use('*', function (req, res) {
    res.render('404.html', {
        title: 'No Found'
    })
});


let server = https.createServer(options, app);

app.listen(3000, function () {
    console.log('服务已运行 3000')
});

server.listen(8000, function () {
    console.log('服务已运行 8000')
});

